package com.study.d9_io_exer;

import java.io.File;

public class DelelteDirectory {
    public static void main(String[] args) {
        deleteDir(new File("C:\\Users\\51230\\Desktop\\os代码"));
    }

    private static void deleteDir(File file) {
        if(!file.exists()||file==null)
            return;
        if(file.isFile()){
            file.delete();
            return;
        }
        File[] files = file.listFiles();
        if(files==null){
            return;
        }
        if(files.length==0){
            file.delete();
            return;
        }
        for (File file1 : files) {
             if(file1.isFile()){
                 file1.delete();
             }else{
                 deleteDir(file1);
             }
        }
        //删掉自己
        file.delete();
    }
}
